import { EnvEnum } from "@/common/enums/env.enum";
import { StrategyEnum } from "@/common/enums/strategy.enum";
import { Injectable } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { PassportStrategy } from "@nestjs/passport";
import { ExtractJwt, Strategy } from "passport-jwt";



@Injectable()
export class JwtRefreshStrategy extends PassportStrategy(
  Strategy,
  StrategyEnum.JWT_REFRESH,
) {
  constructor(private readonly configService: ConfigService) {
    super({
      jwtFromRequest: ExtractJwt.fromBodyField("refreshToken"),
      secretOrKey: Buffer.from(
        configService.get<string>(EnvEnum.JWT_PUBLIC_KEY),
        "base64",
      ).toString("utf-8"),
      algorithms: ["RS256"],
    });
  }

  async validate(payload) {
    return {
      id: payload.id,
    };
  }

}
